package test.dhcp;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

import top.ieei.demo.dhcp.DHCPPacket;

public class DHCPSniffer
{
    private DHCPSniffer()
    {
        throw new UnsupportedOperationException();
    }

    public static void main(String[] args)
    {
        DatagramSocket socket = null;
        try
        {
            socket = new DatagramSocket(67);
            while (true)
            {
                DatagramPacket pac = new DatagramPacket(new byte[1500], 1500);

                socket.receive(pac);
                DHCPPacket dhcp = DHCPPacket.getPacket(pac);
                System.out.println(dhcp.toString());
            }

        } catch (Exception e)
        {
            e.printStackTrace();
        } finally
        {
            socket.close();
        }
    }
}